
* This do file will replicate the analysis presented in Dan Reiter and William Wagstaff,
* "Leadership and Military Effectiveness," to be published in Foreign Policy Analysis.

* There is one data set titled "generals_data1" that contains all of the required data
* to replicate the findings in the paper.

* load data
insheet using "~/Downloads/generals_data1.tab", t clear

***************************************************************
********************** FIGURE 1 *******************************
***************************************************************

graph bar (sum) demotioncommand, over(year) over(allegiance) ytitle(Demotions)

***************************************************************
********************** FIGURE 2 *******************************
***************************************************************

graph bar (sum) promotioncommand, over(year) over(allegiance) ytitle(Promotions)

***************************************************************
********************** TABLE 1 ********************************
***************************************************************

summarize outcomeave2final
summarize outcomeave2final if countrycode == 2
summarize outcomeave2final if countrycode == 255
summarize milacademy if countrycode == 2
summarize ss if countrycode == 255

***************************************************************
********************** TABLE 2 ********************************
***************************************************************

stset counter, id(gennum) failure(compete=1) /* compete = 1 refers to command demotion */
* model one
stcrreg  outcomeave2final  if fighting==1, compete(compete=2) 
* model three
stcrreg  outcomeave2final milacademy if fighting==1 & countrycode == 2, compete(compete=2) 
* model five
stcrreg  outcomeave2final ss if fighting==1 & countrycode == 255, compete(compete=2) tvc(outcomeave2final)

***************************************************************

stset counter, id(gennum) failure(compete=2) /* compete = 2 refers to command promotion */
* model two
stcrreg  outcomeave2final  if fighting==1, compete(compete=1) 
* model four
stcrreg  outcomeave2final milacademy if fighting==1 & countrycode == 2, compete(compete=1) 
* model six
stcrreg  outcomeave2final ss  if fighting==1 & countrycode == 255, compete(compete=1)

***************************************************************
********************** FIGURE 3 *******************************
***************************************************************

stset counter, id(gennum) failure(compete=1) /* compete = 1 refers to command demotion */
stcrreg  outcomeave2final  if fighting==1 , compete(compete=2) 
stcurve, cif at1(outcomeave2final = -1) at2(outcomeave2final = 0) at3(outcomeave2final = 1)

***************************************************************
********************** FIGURE 4 *******************************
***************************************************************

stset counter, id(gennum) failure(compete=1) /* compete = 1 refers to command demotion */
stcrreg  outcomeave2final milacademy if fighting==1 & countrycode==2, compete(compete=2)
stcurve, cif at1(outcomeave2final = -1) at2(outcomeave2final = 0) at3(outcomeave2final = 1)

***************************************************************
********************** FIGURE 5 *******************************
***************************************************************

insheet using "~/Downloads/generals_data1.tab", t clear
stset counter, id(gennum) failure(compete=1) /* compete = 1 refers to command demotion */
gen outcome_count = outcomeave2final*counter
generate id = _n
streset, id(id)
stsplit, at(failures)
stcox  outcomeave2final outcome_count ss if fighting==1 & countrycode==255 
stcurve, cumhaz at1(outcomeave2final = -1) at2(outcomeave2final = 0) at3(outcomeave2final = 1)

***************************************************************
********************** TABLE 3 ********************************
***************************************************************

* reload data because of transformation for Figure 5
insheet using "~/Downloads/generals_data1.tab", t clear

reg  perfchange4 demotiondummy if fighting==1, r cluster(gennum)

***************************************************************
********************** TABLE 4 ********************************
***************************************************************

reg outcome_v2 compar_test_dummy  if compar_test_dummy==1 | compar_test_dummy03==1, r cluster(gennum)

***************************************************************
********************** APPENDIX *******************************
***************************************************************

***************************************************************
********************** TABLE A1 *******************************
***************************************************************

stset counter, id(gennum) failure(compete=1) /* compete = 1 refers to command demotion */
* model one
stcrreg  outcomeave3final  if fighting==1, compete(compete=2) tvc(outcomeave3final)
* model three
stcrreg  outcomeave3final milacademy if fighting==1 & countrycode == 2, compete(compete=2) tvc(outcomeave3final)
* model five
stcrreg  outcomeave3final ss if fighting==1 & countrycode == 255, compete(compete=2) tvc(outcomeave3final)

******

stset counter, id(gennum) failure(compete=2) /* compete = 2 refers to command promotion */
* model two
stcrreg  outcomeave3final  if fighting==1, compete(compete=1)
* model four
stcrreg  outcomeave3final milacademy if fighting==1 & countrycode == 2, compete(compete=1)
* model six
stcrreg  outcomeave3final ss  if fighting==1 & countrycode == 255, compete(compete=1)

***************************************************************
********************** TABLE A2 *******************************
***************************************************************

stset counter, id(gennum) failure(compete=1) /* compete = 1 refers to command demotion */
* model one
stcrreg  outcomeave2final  if fighting==1, compete(compete=2) cluster(divid)
* model three
stcrreg  outcomeave2final milacademy if fighting==1 & countrycode == 2, compete(compete=2) cluster(divid)
* model five
stcrreg  outcomeave2final ss if fighting==1 & countrycode == 255, compete(compete=2) tvc(outcomeave2final) cluster(divid)

******

stset counter, id(gennum) failure(compete=2) /* compete = 2 refers to command promotion */
* model two
stcrreg  outcomeave2final  if fighting==1, compete(compete=1) cluster(divid)
* model four
stcrreg  outcomeave2final milacademy if fighting==1 & countrycode == 2, compete(compete=1) cluster(divid) 
* model six
stcrreg  outcomeave2final ss  if fighting==1 & countrycode == 255, compete(compete=1) cluster(divid)

***************************************************************
********************** TABLE A3 *******************************
***************************************************************

reg  perfchange4 demotiondummy if fighting==1, r cluster(divid)

***************************************************************
********************** TABLE A4 *******************************
***************************************************************

reg outcome_v2 compar_test_dummy  if compar_test_dummy==1 | compar_test_dummy03==1, r cluster(divid)

***************************************************************
********************** TABLE A5 *******************************
***************************************************************

stset counter, id(gennum) failure(compete=1) /* compete = 1 refers to command demotion */
* model one
stcrreg  outcomeave2final  if fighting==1, compete(compete=2) 
* model three
stcrreg  outcomeave2final college if fighting==1 & countrycode == 2, compete(compete=2)
* model five
stcrreg  outcomeave2final ss if fighting==1 & countrycode == 255, compete(compete=2) tvc(outcomeave2final)

******

stset counter, id(gennum) failure(compete=2) /* compete = 2 refers to command promotion */
* model two
stcrreg  outcomeave2final  if fighting==1, compete(compete=1)
* model four
stcrreg  outcomeave2final college if fighting==1 & countrycode == 2, compete(compete=1)
* model six
stcrreg  outcomeave2final ss  if fighting==1 & countrycode == 255, compete(compete=1)

***************************************************************
********************** TABLE A6 *******************************
***************************************************************

stset counter, id(gennum) failure(compete=1) /* compete = 1 refers to command demotion */
* model one
stcrreg  outcomeave2final yearmon italy north_africa if fighting==1, compete(compete=2) 
* model three
stcrreg  outcomeave2final yearmon  milacademy italy north_africa if fighting==1 & countrycode == 2, compete(compete=2)
* model five
stcrreg  outcomeave2final yearmon  ss italy north_africa if fighting==1 & countrycode == 255, compete(compete=2) tvc(outcomeave2final)

******

stset counter, id(gennum) failure(compete=2) /* compete = 2 refers to command promotion */
* model two
stcrreg  outcomeave2final yearmon  italy north_africa  if fighting==1, compete(compete=1)
* model four
stcrreg  outcomeave2final yearmon  milacademy italy north_africa if fighting==1 & countrycode == 2, compete(compete=1)
* model six
stcrreg  outcomeave2final yearmon  ss italy north_africa  if fighting==1 & countrycode == 255, compete(compete=1)

***************************************************************
********************** TABLE A7 *******************************
***************************************************************

reg  perfchange4 demotiondummy batcommand regbrigcommand milacademy countrycode yearmon north_africa w_europe if fighting==1, r cluster(gennum)

***************************************************************
********************** TABLE A8 *******************************
***************************************************************

reg outcome_v2 compar_test_dummy batcommand regbrigcommand milacademy countrycode yearmon north_africa w_europe if compar_test_dummy==1 | compar_test_dummy03==1, r cluster(gennum)


******************** END OF FILE ******************************

